package com.thinkcube.edutainment.adapters;

import java.util.List;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.thinkcube.edutainment.domain.data.PostData;
import com.thinkcube.edutainment.service.viewitem.ForumPostItem;
import com.thinkcube.edutainment.service.viewitem.ForumPostItem_;

@EBean
public class ForumPostAdapter extends BaseAdapter {

	List<PostData> postData;

	@RootContext
	Context context;

	@Override
	public View getView(final int position, final View convertView,
			final ViewGroup parent) {

		ForumPostItem forumPostItem;
		if (convertView == null) {
			forumPostItem = ForumPostItem_.build(context);
		} else {
			forumPostItem = (ForumPostItem) convertView;
		}

		forumPostItem.bind(getItem(position));

		return forumPostItem;
	}

	public List<PostData> getPostData() {
		return postData;
	}

	public void setPostData(List<PostData> postData) {
		this.postData = postData;
	}

	@Override
	public int getCount() {
		return postData.size();
	}

	@Override
	public PostData getItem(final int position) {
		return postData.get(position);
	}

	@Override
	public long getItemId(final int position) {
		return position;
	}

}
